<script type="text/javascript">
    $(function() {
        $.fn.dataGridOptions.formSubFun("#form",'/modules/additional/drawLottery/lotteryDoAdd.html');
    });
</script>
<form id="form" method="post" enctype="multipart/form-data">
<div class="popForm sForm">
	<div class="formitm">
		<label class="lab">名称：</label>
		<div class="ipt"><input type="text" name="name" class="easyui-validatebox validatebox-text" data-options="required: true, validType:'maxLength[15]'"></div>
	</div>
	<div class="formitm">
		<label class="lab">抽奖类别：</label>
		<div class="ipt">
			<select name="category" id="category">
				<option value="1">积分抽奖</option>
				<option value="2">签到抽奖</option>
			</select>
		</div>
	</div>
	<div class="formitm">
		<label class="lab">状态：</label>
		<div class="ipt">
			<select name="status" id="status">
				<option value="1">启用</option>
				<option value="0">禁用</option>
			</select>
		</div>
	</div>
	<div class="formitm">
		<label class="lab">类型：</label>
		<div class="ipt">
			<select name="type" id="type">
				<option value="1">积分</option>
				<option value="2">现金</option>
				<option value="3">加息券</option>
				<option value="4">抽奖</option>
				<option value="5">电影票</option>
				<option value="6">现金红包</option>
				<option value="9">虚拟红包</option>
				<option value="7">体验券</option>
				<option value="8">实物</option>
				<option value="0">未中奖</option>
			</select>
		</div>
	</div>

	<div  id="ruleList" style="display: none">
		<label class="lab">规则列表：</label>
		<div class="ipt">
			<select name="itemId" id="itemId">
				<option>----请选择----</option>
			</select>
		</div>
	</div>

	<div class="formitm">
		<label class="lab">中奖率：</label>
		<div class="ipt"><input type="text" name="rate" id="rate" class="easyui-validatebox validatebox-text" data-options="required: true,validType:'lotteryRate[0,1]'" maxlength="5" style="width:80px;">&nbsp;介于0～1之间</div>
	</div>
	<div class="formitm" id="valueDiv">
		<label class="lab">中奖值：</label>
		<div class="ipt"><input type="text" name="value" id="value" class="easyui-validatebox validatebox-text" maxlength="6" style="width:80px;">&nbsp;<span id="unit">积分</span></div>
	</div>
	<div class="formitm">
		<label class="lab">位置：</label>
		<div class="ipt"><input type="text" name="pos" class="easyui-validatebox validatebox-text" data-options="required: true, validType:'numOnly'">&nbsp;转盘上顺时针顺序</div>
	</div>
	<div class="formitm">
		<label class="lab">有效期类型:</label>
		<div class="ipt">
			<select name="validDayType" id="validDayType">
				<option value="1" selected="selected">天</option>
				<option value="2">月</option>
			</select>
		</div>
	</div>
	<div class="formitm">
		<label class="lab">有效期(天)：</label>
		<div class="ipt">
			<input type="text" name="validDay" class="easyui-validatebox validatebox-text" data-options="required: true, validType:'numOnly'">&nbsp;<span id="timeUnit">天</span>
		</div>
	</div>
</div>
 </form>
 <script>
 	var typeVal;
	$("#type").change(function(){
		typeVal=$(this).val();
		switch (typeVal) {
			case '1' :
				$("#ruleList").hide();
				$("#valueDiv").show();
				$("#unit").text("积分");
				break;
			case '2' :
				$("#ruleList").hide();
				$("#valueDiv").show();
				$("#unit").text("元");
				break;
			case '3' :
				$("#valueDiv").hide();
				$("#unit").text("额度加息券");
				upRateListFn();
				break;
			case '4' :
				$("#ruleList").hide();
				$("#valueDiv").show();
				$("#unit").text("次抽奖");
				break;
			case '5' :
				$("#ruleList").hide();
				$("#valueDiv").show();
				$("#unit").text("张电影票");
				break;
			case '6' :
				$("#ruleList").hide();
				$("#valueDiv").show();
				$("#unit").text("元现金红包");
				break;
			case '7' :
				$("#valueDiv").hide();
				$("#unit").text("元体验券");
				experienceListFn();
				break;
			case '8' :
				$("#valueDiv").hide();
				$("#unit").text("");
				commodityListFn();
				break;
			case '9' :
				$("#ruleList").hide();
				$("#valueDiv").show();
				$("#unit").text("元虚拟红包");
				break;
			case '0' :
				$("#ruleList").hide();
				$("#valueDiv").show();
				$("#unit").text("");
				break;
		}
	});
	$("#validDayType").change(function(){
		 typeVal = $(this).val();
		 if(typeVal == 1) {
			 $("#timeUnit").text("天")
		 }else if(typeVal ==2){
			 $("#timeUnit").text("月")
		 }
	 });
	//展示奖品为商品的列表
	 function commodityListFn(){
		 $.post("/modules/additional/commodity/jsonLotteryCommodityList.html",
			 {
				 category : $("#category").val()
			 },
			 function(data,status){
				 var data = eval(data);
				 $("#ruleList").show();
				 $('#itemId option:gt(0)').remove();
				 $.each(data, function(index, item){
					 $("#itemId").append($('<option value="'+item.commodityId+'">'+item.commodityName+'</option>'));//后台数据加到下拉框
				 });
			 }
		 )
	 }
	//展示加息券列表
	function upRateListFn(){
		$.post("/modules/additional/upRate/usableUpRateList.html",
			{
			},
			function(data,status){
				var data = eval(data);
				$("#ruleList").show();
				$('#itemId option:gt(0)').remove();
				$.each(data, function(index, item){
					$("#itemId").append($('<option value="'+item.ruleId+'">'+item.ruleName+'</option>'));//后台数据加到下拉框
				});
			}
		)
	}
	//展示体验金列表
	function experienceListFn(){
		$.post("/modules/additional/experienceRule/experienceRuleJson.html",
			{
			},
			function(data,status){
				var data = eval(data);
				$("#ruleList").show();
				$('#itemId option:gt(0)').remove();
				$.each(data, function(index, item){
					$("#itemId").append($('<option value="'+item.ruleId+'">'+item.ruleName+'</option>'));//后台数据加到下拉框
				});
			}
		)
	}
 </script>

